﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Cn.Edwon.Spring;
using Cn.Edwon.Web.Support;
using Cn.Cellula.Biz;
using Cn.Cellula.Biz.Port;
using Cn.Edwon.Web;
using Cn.Cellula.Client;

namespace Cn.Cellula.Website.Admin.Content.Dept {
    public partial class List : PageSupport, ICellulaBiz {
        IDeptBiz biz = BizFactory.Get<IDeptBiz>();
        protected void Page_Load(object sender, EventArgs e) {
            if (!Page.IsPostBack) {
                InitForm();
                LoadDept(null);
            }
        }

        private void InitForm() {
        }
        private void LoadDept(String ParentKey) {
            this.lab_DeptData.Text = "<script type=\"text/javascript\">var DeptData = " + biz.LoadDept2Json(this.OwnerKey, null) + ";</script>";
        }
        protected void btn_type_add_Click(object sender, EventArgs e) {
            String parms = Request.Form["cbx_Dept"];
            if (!String.IsNullOrEmpty(parms)) {
                String[] keys = parms.Split(',');
                Response.Redirect("Edit.aspx?pid=" + keys[0]);
            } else {
                Response.Redirect("Edit.aspx");
            }
        }

        protected void btn_type_update_Click(object sender, EventArgs e) {
            String parms = Request.Form["cbx_Dept"];
            if (!String.IsNullOrEmpty(parms)) {
                String[] keys = parms.Split(',');
                Response.Redirect("Edit.aspx?id=" + keys[0]);
            } else {
                SiteInfo.Send(Page, TxtDef.ERROR, TxtDef.NoEditSelect);
            }
        }

        protected void btn_type_delete_Click(object sender, EventArgs e) {
            String parms = Request.Form["cbx_Dept"];
            if (!String.IsNullOrEmpty(parms)) {
                String[] keys = parms.Split(',');
                try {
                    biz.DeleteCategories(keys, this.OwnerKey);
                    BizFactory.Get<ILogBiz>().LogDelete("产品分类", keys.Length, this.Actor, Request);
                } catch (Exception ex) {
                    SiteInfo.Send(Page, TxtDef.ERROR, ex.Message);
                }
                this.LoadDept(null);
            } else {
                SiteInfo.Send(Page, TxtDef.ERROR, TxtDef.NoDelSelect);
            }
        }

        protected void ddl_type_SelectedIndexChanged(object sender, EventArgs e) {
            this.LoadDept(null);
        }


        #region ICellulaBiz 成员

        public string ModelName {
            get { return CodeTypeDef.Module.Dept; }
        }

        #endregion

        protected void ddl_DeptType_SelectedIndexChanged(object sender, EventArgs e) {
            Response.Redirect("List.aspx");
        }
    }
}